const mongoose = require('mongoose');
const Schema = mongoose.Schema;

mongoose.connect('mongodb://localhost/onenet', {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useFindAndModify: false,
    useCreateIndex: true
});

const db = mongoose.connection;

db.on('open', () => {
    console.log('mongodb connected');
});

db.on('error', (error) => {
    console.log(error);
});

const dataSchema = new  Schema({
    projectId: {
        type: String
    }, 
    productId: {
        type: String
    }, 
    deviceName: {
        type: String
    }, 
    messageType: {
        String
    }, 
    notifyType: {
        type: String
    }, 
    signature: {
        type: String
    },
    pushId: {// the push id
        type: String
    },
    nonce: {
        type: String
    },
    pushTime: { // the push time
        type: Date
    },
    data: {
        type: String
    }
});

module.exports = mongoose.model('Msg',dataSchema);